<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<t:base type="jquery,easyui,tools,DatePicker,ckeditor"></t:base>
    <script type="text/javascript" src="${webRoot}/plug-in/ajaxfileupload/ajaxfileupload.js"></script>
</head>
<body style="overflow-y: auto" scroll="no">
<t:formvalid formid="formobj" dialog="true" usePlugin="password" layout="div" action="adController.do?saveAd">
	<input id="id" name="id" type="hidden" value="${map.id }">
	<input id="pid" name="pid" type="hidden" value="${pid }">
	<fieldset class="step" id="step_fieldset" style="height: 270px;">
        <div class="form">
            <label class="Validform_label">名称:</label>
            <input class="inputxt" id="name" name="name" value="${map.name}" datatype="*" maxlength="40">
            <span class="Validform_checktip"></span>
        </div>
        <div class="form">
            <label class="Validform_label">URL:</label>
            <input class="inputxt" id="url" name="url" value="${map.url}" maxlength="128" style="width: 420px;">
        </div>
        <div class="form">
            <label class="Validform_label">排序:</label>
            <input class="inputxt" id="showIndex" name="showIndex" value="${map.showIndex}" datatype="n" maxlength="3">
            <span class="Validform_checktip"></span>
        </div>
        <div class="form">
            <label class="Validform_label">是否启用:</label>
            启用<input class="inputxt" name="enable" type="radio" ignore="ignore" value="1" checked style="width:40px;">
            禁用<input class="inputxt" name="enable" type="radio" ignore="ignore" value="0" style="width:40px;">
            <span class="Validform_checktip"></span>
        </div>
        <div class="form">
            <img id="picImg" src="${webRoot}/${map.pic}" style="width: 100px;height: 100px;" alt="广告图片" title="pic">

            <input type="button" name="" onclick="javascript:$(this).next().trigger('click')" class="uploadify-button" value="上传图片" />
            <input  type="file" style="display: none;" name="file" id="fulAchievements1" onchange="f_file_upload('fulAchievements1')" />
            <input type="hidden" name="picPath" id="picPath" value="${map.pic}" datatype="*" nullmsg="请上传广告图片"/>
            <span class="Validform_checktip"></span>
        </div>
	</fieldset>
</t:formvalid>
<script>
    $(function() {
        var enable = '${map.enable}';
        if(enable == 'false'){
            $("input[name='enable'][value=0]").attr("checked",true);
        }else{
            $("input[name='enable'][value=1]").attr("checked",true);
        }

    });

    //Ajax文件上传
    function f_file_upload(fileInputId){
        var path = $("#"+fileInputId).val();

        var pos1 = path.lastIndexOf("\\");
        var pos2 = path.lastIndexOf(".");
        var fileName = path.substring(pos1 + 1,pos2);

        var result = path.substring(pos2 + 1, path.length );

        var imgs = ".bmp.jpg.dib.jpeg.png.jfif.jpe.tif.tiff.gif.BMP.JPG.DIB.JPEG.PNG.JFIF.JPE.TIF.TIFF.GIF";

        //文件类型 false为压缩包
        var boo = false;

        //判断上传的是项目图片还是项目附件
        if("fulAchievements1" == fileInputId){
            if(imgs.indexOf(result) > -1){
                boo = true;
            }else{
                alert("只能上传后缀为 "+imgs+" 的图片！");
                $("#"+fileInputId).val("");
                return;
            }
        }

        $.ajaxFileUpload({
            url: '${webRoot}/adController.do?uploadAdPic',
            secureuri: false,
            fileElementId: fileInputId,
            //dataType: 'json',
            success: function (data) {
                var data2 = data.split(",");

                var url = data2[0].replace(" ","");
                fileName = data2[1].replace(" ","");

                $("#picPath").val(url);
                $("#picImg").attr("src","${webRoot}/" + url);
            },
            error:function(data){
                console.log("error");
                console.log(data);
            }
        });
    }
</script>
</body>